home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / generic / tkScale.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  8.0 KB  |  226 lines  |  [TEXT/CWIE]

  1. /*
  2.  * tkScale.h --
  3.  *
  4.  *    Declarations of types and functions used to implement
  5.  *    the scale widget.
  6.  *
  7.  * Copyright (c) 1996 by Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  *
  12.  * SCCS: @(#) tkScale.h 1.5 96/07/08 12:56:56
  13.  */
  14.  
  15. #ifndef _TKSCALE
  16. #define _TKSCALE
  17.  
  18. #ifndef _TK
  19. #include "tk.h"
  20. #endif
  21.  
  22. /*
  23.  * A data structure of the following type is kept for each scale
  24.  * widget managed by this file:
  25.  */
  26.  
  27. typedef struct TkScale {
  28.     Tk_Window tkwin;        /* Window that embodies the scale.  NULL
  29.                  * means that the window has been destroyed
  30.                  * but the data structures haven't yet been
  31.                  * cleaned up.*/
  32.     Display *display;        /* Display containing widget.  Used, among
  33.                  * other things, so that resources can be
  34.                  * freed even after tkwin has gone away. */
  35.     Tcl_Interp *interp;        /* Interpreter associated with scale. */
  36.     Tcl_Command widgetCmd;    /* Token for scale's widget command. */
  37.     Tk_Uid orientUid;        /* Orientation for window ("vertical" or
  38.                  * "horizontal"). */
  39.     int vertical;        /* Non-zero means vertical orientation,
  40.                  * zero means horizontal. */
  41.     int width;            /* Desired narrow dimension of scale,
  42.                  * in pixels. */
  43.     int length;            /* Desired long dimension of scale,
  44.                  * in pixels. */
  45.     double value;        /* Current value of scale. */
  46.     char *varName;        /* Name of variable (malloc'ed) or NULL.
  47.                  * If non-NULL, scale's value tracks
  48.                  * the contents of this variable and
  49.                  * vice versa. */
  50.     double fromValue;        /* Value corresponding to left or top of
  51.                  * scale. */
  52.     double toValue;        /* Value corresponding to right or bottom
  53.                  * of scale. */
  54.     double tickInterval;    /* Distance between tick marks;  0 means
  55.                  * don't display any tick marks. */
  56.     double resolution;        /* If > 0, all values are rounded to an
  57.                  * even multiple of this value. */
  58.     int digits;            /* Number of significant digits to print
  59.                  * in values.  0 means we get to choose the
  60.                  * number based on resolution and/or the
  61.                  * range of the scale. */
  62.     char format[10];        /* Sprintf conversion specifier computed from
  63.                  * digits and other information. */
  64.     double bigIncrement;    /* Amount to use for large increments to
  65.                  * scale value.  (0 means we pick a value). */
  66.     char *command;        /* Command prefix to use when invoking Tcl
  67.                  * commands because the scale value changed.
  68.                  * NULL means don't invoke commands.
  69.                  * Malloc'ed. */
  70.     int repeatDelay;        /* How long to wait before auto-repeating
  71.                  * on scrolling actions (in ms). */
  72.     int repeatInterval;        /* Interval between autorepeats (in ms). */
  73.     char *label;        /* Label to display above or to right of
  74.                  * scale;  NULL means don't display a
  75.                  * label.  Malloc'ed. */
  76.     int labelLength;        /* Number of non-NULL chars. in label. */
  77.     Tk_Uid state;        /* Normal or disabled.  Value cannot be
  78.                  * changed when scale is disabled. */
  79.  
  80.     /*
  81.      * Information used when displaying widget:
  82.      */
  83.  
  84.     int borderWidth;        /* Width of 3-D border around window. */
  85.     Tk_3DBorder bgBorder;    /* Used for drawing slider and other
  86.                  * background areas. */
  87.     Tk_3DBorder activeBorder;    /* For drawing the slider when active. */
  88.     int sliderRelief;        /* Is slider to be drawn raised, sunken, etc. */
  89.     XColor *troughColorPtr;    /* Color for drawing trough. */
  90.     GC troughGC;        /* For drawing trough. */
  91.     GC copyGC;            /* Used for copying from pixmap onto screen. */
  92.     Tk_Font tkfont;        /* Information about text font, or NULL. */
  93.     XColor *textColorPtr;    /* Color for drawing text. */
  94.     GC textGC;            /* GC for drawing text in normal mode. */
  95.     int relief;            /* Indicates whether window as a whole is
  96.                  * raised, sunken, or flat. */
  97.     int highlightWidth;        /* Width in pixels of highlight to draw
  98.                  * around widget when it has the focus.
  99.                  * <= 0 means don't draw a highlight. */
  100.     XColor *highlightBgColorPtr;
  101.                 /* Color for drawing traversal highlight
  102.                  * area when highlight is off. */
  103.     XColor *highlightColorPtr;    /* Color for drawing traversal highlight. */
  104.     int inset;            /* Total width of all borders, including
  105.                  * traversal highlight and 3-D border.
  106.                  * Indicates how much interior stuff must
  107.                  * be offset from outside edges to leave
  108.                  * room for borders. */
  109.     int sliderLength;        /* Length of slider, measured in pixels along
  110.                  * long dimension of scale. */
  111.     int showValue;        /* Non-zero means to display the scale value
  112.                  * below or to the left of the slider;  zero
  113.                  * means don't display the value. */
  114.  
  115.     /*
  116.      * Layout information for horizontal scales, assuming that window
  117.      * gets the size it requested:
  118.      */
  119.  
  120.     int horizLabelY;        /* Y-coord at which to draw label. */
  121.     int horizValueY;        /* Y-coord at which to draw value text. */
  122.     int horizTroughY;        /* Y-coord of top of slider trough. */
  123.     int horizTickY;        /* Y-coord at which to draw tick text. */
  124.     /*
  125.      * Layout information for vertical scales, assuming that window
  126.      * gets the size it requested:
  127.      */
  128.  
  129.     int vertTickRightX;        /* X-location of right side of tick-marks. */
  130.     int vertValueRightX;    /* X-location of right side of value string. */
  131.     int vertTroughX;        /* X-location of scale's slider trough. */
  132.     int vertLabelX;        /* X-location of origin of label. */
  133.  
  134.     /*
  135.      * Miscellaneous information:
  136.      */
  137.  
  138.     Tk_Cursor cursor;        /* Current cursor for window, or None. */
  139.     char *takeFocus;        /* Value of -takefocus option;  not used in
  140.                  * the C code, but used by keyboard traversal
  141.                  * scripts.  Malloc'ed, but may be NULL. */
  142.     int flags;            /* Various flags;  see below for
  143.                  * definitions. */
  144. } TkScale;
  145.  
  146. /*
  147.  * Flag bits for scales:
  148.  *
  149.  * REDRAW_SLIDER -        1 means slider (and numerical readout) need
  150.  *                to be redrawn.
  151.  * REDRAW_OTHER -        1 means other stuff besides slider and value
  152.  *                need to be redrawn.
  153.  * REDRAW_ALL -            1 means the entire widget needs to be redrawn.
  154.  * ACTIVE -            1 means the widget is active (the mouse is
  155.  *                in its window).
  156.  * INVOKE_COMMAND -        1 means the scale's command needs to be
  157.  *                invoked during the next redisplay (the
  158.  *                value of the scale has changed since the
  159.  *                last time the command was invoked).
  160.  * SETTING_VAR -        1 means that the associated variable is
  161.  *                being set by us, so there's no need for
  162.  *                ScaleVarProc to do anything.
  163.  * NEVER_SET -            1 means that the scale's value has never
  164.  *                been set before (so must invoke -command and
  165.  *                set associated variable even if the value
  166.  *                doesn't appear to have changed).
  167.  * GOT_FOCUS -            1 means that the focus is currently in
  168.  *                this widget.
  169.  */
  170.  
  171. #define REDRAW_SLIDER        1
  172. #define REDRAW_OTHER        2
  173. #define REDRAW_ALL        3
  174. #define ACTIVE            4
  175. #define INVOKE_COMMAND        0x10
  176. #define SETTING_VAR        0x20
  177. #define NEVER_SET        0x40
  178. #define GOT_FOCUS        0x80
  179.  
  180. /*
  181.  * Symbolic values for the active parts of a slider.  These are
  182.  * the values that may be returned by the ScaleElement procedure.
  183.  */
  184.  
  185. #define OTHER        0
  186. #define TROUGH1        1
  187. #define SLIDER        2
  188. #define TROUGH2        3
  189.  
  190. /*
  191.  * Space to leave between scale area and text, and between text and
  192.  * edge of window.
  193.  */
  194.  
  195. #define SPACING 2
  196.  
  197. /*
  198.  * How many characters of space to provide when formatting the
  199.  * scale's value:
  200.  */
  201.  
  202. #define PRINT_CHARS 150
  203.  
  204. /*
  205.  * Declaration of procedures used in the implementation of the scrollbar
  206.  * widget. 
  207.  */
  208.  
  209. EXTERN void        TkEventuallyRedrawScale _ANSI_ARGS_((TkScale *scalePtr,
  210.                 int what));
  211. EXTERN double        TkRoundToResolution _ANSI_ARGS_((TkScale *scalePtr,
  212.                 double value));
  213. EXTERN TkScale *    TkpCreateScale _ANSI_ARGS_((Tk_Window tkwin));
  214. EXTERN void        TkpDestroyScale _ANSI_ARGS_((TkScale *scalePtr));
  215. EXTERN void        TkpDisplayScale _ANSI_ARGS_((ClientData clientData));
  216. EXTERN double        TkpPixelToValue _ANSI_ARGS_((TkScale *scalePtr, 
  217.                 int x, int y));
  218. EXTERN int        TkpScaleElement _ANSI_ARGS_((TkScale *scalePtr,
  219.                  int x, int y));
  220. EXTERN void        TkpSetScaleValue _ANSI_ARGS_((TkScale *scalePtr,
  221.                 double value, int setVar, int invokeCommand));
  222. EXTERN int        TkpValueToPixel _ANSI_ARGS_((TkScale *scalePtr,
  223.                 double value));
  224.  
  225. #endif /* _TKSCALE */
  226.